<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学号" prop="stuNo">
        <el-input v-model="queryParams.stuNo" placeholder="请输入学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="班级id" prop="classId">
        <el-input v-model="queryParams.classId" placeholder="请输入班级id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="班级代码" prop="classCode">
        <el-input v-model="queryParams.classCode" placeholder="请输入班级代码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学年id" prop="stuYearId">
        <el-input v-model="queryParams.stuYearId" placeholder="请输入学年id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input v-model="queryParams.idCard" placeholder="请输入身份证号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="银行卡号" prop="bankCard">
        <el-input v-model="queryParams.bankCard" placeholder="请输入银行卡号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="开户行" prop="bankAddr">
        <el-input v-model="queryParams.bankAddr" placeholder="请输入开户行" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="辅导员意见" prop="fdyCmt">
        <el-input v-model="queryParams.fdyCmt" placeholder="请输入辅导员意见" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学务意见" prop="xwCmt">
        <el-input v-model="queryParams.xwCmt" placeholder="请输入学务意见" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学工处意见" prop="jwcCmt">
        <el-input v-model="queryParams.jwcCmt" placeholder="请输入学工处意见" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="辅导员姓名" prop="fdyName">
        <el-input v-model="queryParams.fdyName" placeholder="请输入辅导员姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="班主任姓名" prop="bzrName">
        <el-input v-model="queryParams.bzrName" placeholder="请输入班主任姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="辅导员工号" prop="fdyNo">
        <el-input v-model="queryParams.fdyNo" placeholder="请输入辅导员工号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="班主任工号" prop="bzrNo">
        <el-input v-model="queryParams.bzrNo" placeholder="请输入班主任工号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="提交时间" prop="applyTime">
        <el-date-picker clearable v-model="queryParams.applyTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择提交时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="学生人数" prop="classCount">
        <el-input v-model="queryParams.classCount" placeholder="请输入学生人数" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['comprehensive:newClassGoodApply:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['comprehensive:newClassGoodApply:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['comprehensive:newClassGoodApply:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['comprehensive:newClassGoodApply:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="newClassGoodApplyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="#" align="center" prop="id" />
      <el-table-column label="学号" align="center" prop="stuNo" />
      <el-table-column label="班级id" align="center" prop="classId" />
      <el-table-column label="班级代码" align="center" prop="classCode" />
      <el-table-column label="学年id" align="center" prop="stuYearId" />
      <el-table-column label="身份证号" align="center" prop="idCard" />
      <el-table-column label="银行卡号" align="center" prop="bankCard" />
      <el-table-column label="开户行" align="center" prop="bankAddr" />
      <el-table-column label="审核状态" align="center" prop="applyStatus" />
      <el-table-column label="辅导员意见" align="center" prop="fdyCmt" />
      <el-table-column label="学务意见" align="center" prop="xwCmt" />
      <el-table-column label="学工处意见" align="center" prop="jwcCmt" />
      <el-table-column label="所获奖励" align="center" prop="goodHis" />
      <el-table-column label="主要事迹" align="center" prop="mainHis" :formatter="truncateFormatter" />
      <el-table-column label="辅导员姓名" align="center" prop="fdyName" />
      <el-table-column label="班主任姓名" align="center" prop="bzrName" />
      <el-table-column label="辅导员工号" align="center" prop="fdyNo" />
      <el-table-column label="班主任工号" align="center" prop="bzrNo" />
      <el-table-column label="提交时间" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="学生人数" align="center" prop="classCount" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['comprehensive:newClassGoodApply:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['comprehensive:newClassGoodApply:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改先进班集体对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学号" prop="stuNo">
          <el-input v-model="form.stuNo" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="班级id" prop="classId">
          <el-input v-model="form.classId" placeholder="请输入班级id" />
        </el-form-item>
        <el-form-item label="班级代码" prop="classCode">
          <el-input v-model="form.classCode" placeholder="请输入班级代码" />
        </el-form-item>
        <el-form-item label="学年id" prop="stuYearId">
          <el-input v-model="form.stuYearId" placeholder="请输入学年id" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCard">
          <el-input v-model="form.bankCard" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="开户行" prop="bankAddr">
          <el-input v-model="form.bankAddr" placeholder="请输入开户行" />
        </el-form-item>
        <el-form-item label="辅导员意见" prop="fdyCmt">
          <el-input v-model="form.fdyCmt" placeholder="请输入辅导员意见" />
        </el-form-item>
        <el-form-item label="学务意见" prop="xwCmt">
          <el-input v-model="form.xwCmt" placeholder="请输入学务意见" />
        </el-form-item>
        <el-form-item label="学工处意见" prop="jwcCmt">
          <el-input v-model="form.jwcCmt" placeholder="请输入学工处意见" />
        </el-form-item>
        <el-form-item label="所获奖励" prop="goodHis">
          <el-input v-model="form.goodHis" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="主要事迹" prop="mainHis">
          <el-input v-model="form.mainHis" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="辅导员姓名" prop="fdyName">
          <el-input v-model="form.fdyName" placeholder="请输入辅导员姓名" />
        </el-form-item>
        <el-form-item label="班主任姓名" prop="bzrName">
          <el-input v-model="form.bzrName" placeholder="请输入班主任姓名" />
        </el-form-item>
        <el-form-item label="辅导员工号" prop="fdyNo">
          <el-input v-model="form.fdyNo" placeholder="请输入辅导员工号" />
        </el-form-item>
        <el-form-item label="班主任工号" prop="bzrNo">
          <el-input v-model="form.bzrNo" placeholder="请输入班主任工号" />
        </el-form-item>
        <el-form-item label="提交时间" prop="applyTime">
          <el-date-picker clearable v-model="form.applyTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择提交时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="学生人数" prop="classCount">
          <el-input v-model="form.classCount" placeholder="请输入学生人数" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNewClassGoodApply, getNewClassGoodApply, delNewClassGoodApply, addNewClassGoodApply, updateNewClassGoodApply } from "@/api/stuCQS/good-class/newClassGoodApply";

export default {
  name: "NewClassGoodApply",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 先进班集体表格数据
      newClassGoodApplyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuNo: null,
        classId: null,
        classCode: null,
        stuYearId: null,
        idCard: null,
        bankCard: null,
        bankAddr: null,
        applyStatus: null,
        fdyCmt: null,
        xwCmt: null,
        jwcCmt: null,
        goodHis: null,
        mainHis: null,
        fdyName: null,
        bzrName: null,
        fdyNo: null,
        bzrNo: null,
        applyTime: null,
        classCount: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询先进班集体列表 */
    getList() {
      this.loading = true;
      listNewClassGoodApply(this.queryParams).then(response => {
        this.newClassGoodApplyList = response.rows;
        console.log(this.newClassGoodApplyList)
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stuNo: null,
        classId: null,
        classCode: null,
        stuYearId: null,
        idCard: null,
        bankCard: null,
        bankAddr: null,
        applyStatus: null,
        fdyCmt: null,
        xwCmt: null,
        jwcCmt: null,
        goodHis: null,
        mainHis: null,
        fdyName: null,
        bzrName: null,
        fdyNo: null,
        bzrNo: null,
        applyTime: null,
        classCount: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加先进班集体";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNewClassGoodApply(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改先进班集体";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNewClassGoodApply(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNewClassGoodApply(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //主要事迹字数显示
    truncateFormatter(row, column, cellValue) {
      if (cellValue && cellValue.length > 100) {
        return cellValue.substring(0, 10) + '...';
      }
      return cellValue;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除先进班集体编号为"' + ids + '"的数据项？').then(function () {
        return delNewClassGoodApply(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('comprehensive/newClassGoodApply/export', {
        ...this.queryParams
      }, `newClassGoodApply_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
